﻿using AdverseEventReportSystem.BLL.SchedulingSystem;
using AdverseEventReportSystem.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdverseEventReportSystem.BLL.Scheduling
{
    /// <summary>
    /// 假期类型
    /// </summary>
    public class HolidayTypeManager
    {
        /// <summary>
        /// 保存假期类型
        /// </summary>
        /// <param name="holidayTypeSetting">对象</param>
        /// <returns></returns>
        public static OperateResult SaveHolidayType(HolidayTypeSetting holidayTypeSetting)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfBoolean result = service.SaveHolidayType(holidayTypeSetting);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;

        }

        /// <summary>
        /// 获取假期类型列表
        /// </summary>
        ///<param name="pageIndex">页索引</param>
        ///<param name="pageSize">页大小</param>
        /// <returns></returns>
        public static OperateResult GetHolidayTypeList(int pageIndex, int pageSize)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SysLoginUser loginUser = LoginManager.GetLoginUser();
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfString result = service.GetHolidayTypeList(pageIndex, pageSize, loginUser.CurrDepCode);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 获取单个假期类型
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        public static OperateResult GetHolidayType(int id)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfHolidayTypeSetting result = service.GetHolidayType(id);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
    }
}
